{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "lstm",
      "version": "0.3.2",
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/dragen1860/DeepLearningTutorialsCN/blob/master/lstm.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "metadata": {
        "id": "xazrh9eIcgTO",
        "colab_type": "code",
        "outputId": "93fdc997-1c20-48ea-c479-7202b3ae2577",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 591
        }
      },
      "cell_type": "code",
      "source": [
        "!pip install torch\n",
        "!pip install torchtext\n",
        "!python -m spacy download en\n",
        "\n",
        "\n",
        "# K80 gpu for 12 hours\n",
        "import torch\n",
        "from torch import nn, optim\n",
        "from torchtext import data, datasets\n",
        "\n",
        "print('GPU:', torch.cuda.is_available())"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Collecting torch\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/7e/60/66415660aa46b23b5e1b72bc762e816736ce8d7260213e22365af51e8f9c/torch-1.0.0-cp36-cp36m-manylinux1_x86_64.whl (591.8MB)\n",
            "\u001b[K    100% |████████████████████████████████| 591.8MB 28kB/s \n",
            "tcmalloc: large alloc 1073750016 bytes == 0x61892000 @  0x7f9c7645b2a4 0x591a07 0x5b5d56 0x502e9a 0x506859 0x502209 0x502f3d 0x506859 0x504c28 0x502540 0x502f3d 0x506859 0x504c28 0x502540 0x502f3d 0x506859 0x504c28 0x502540 0x502f3d 0x507641 0x502209 0x502f3d 0x506859 0x504c28 0x502540 0x502f3d 0x507641 0x504c28 0x502540 0x502f3d 0x507641\n",
            "\u001b[?25hInstalling collected packages: torch\n",
            "Successfully installed torch-1.0.0\n",
            "Collecting torchtext\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/c6/bc/b28b9efb4653c03e597ed207264eea45862b5260f48e9f010b5068d64db1/torchtext-0.3.1-py3-none-any.whl (62kB)\n",
            "\u001b[K    100% |████████████████████████████████| 71kB 2.7MB/s \n",
            "\u001b[?25hRequirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from torchtext) (4.28.1)\n",
            "Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from torchtext) (2.18.4)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from torchtext) (1.14.6)\n",
            "Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from torchtext) (1.0.0)\n",
            "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->torchtext) (3.0.4)\n",
            "Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->torchtext) (2.6)\n",
            "Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->torchtext) (1.22)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->torchtext) (2018.11.29)\n",
            "Installing collected packages: torchtext\n",
            "Successfully installed torchtext-0.3.1\n",
            "Collecting en_core_web_sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#egg=en_core_web_sm==2.0.0\n",
            "\u001b[?25l  Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB)\n",
            "\u001b[K    100% |████████████████████████████████| 37.4MB 46.8MB/s \n",
            "\u001b[?25hInstalling collected packages: en-core-web-sm\n",
            "  Running setup.py install for en-core-web-sm ... \u001b[?25l-\b \b\\\b \b|\b \bdone\n",
            "\u001b[?25hSuccessfully installed en-core-web-sm-2.0.0\n",
            "\n",
            "\u001b[93m    Linking successful\u001b[0m\n",
            "    /usr/local/lib/python3.6/dist-packages/en_core_web_sm -->\n",
            "    /usr/local/lib/python3.6/dist-packages/spacy/data/en\n",
            "\n",
            "    You can now load the model via spacy.load('en')\n",
            "\n",
            "GPU: True\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "sPOkbQz1dfMS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        },
        "outputId": "4c31cbd3-48bd-446f-cf62-5e008506ba54"
      },
      "cell_type": "code",
      "source": [
        "torch.manual_seed(123)\n",
        "\n",
        "TEXT = data.Field(tokenize='spacy')\n",
        "LABEL = data.LabelField(dtype=torch.float)\n",
        "train_data, test_data = datasets.IMDB.splits(TEXT, LABEL)"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "downloading aclImdb_v1.tar.gz\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "stream",
          "text": [
            "aclImdb_v1.tar.gz: 100%|██████████| 84.1M/84.1M [00:07<00:00, 11.4MB/s]\n"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "metadata": {
        "id": "LodNOFuEeRuv",
        "colab_type": "code",
        "outputId": "e1ea0131-5d5c-4bb6-8a81-b81785563016",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        }
      },
      "cell_type": "code",
      "source": [
        "print('len of train data:', len(train_data))\n",
        "print('len of test data:', len(test_data))"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "len of train data: 25000\n",
            "len of test data: 25000\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "gnQaJuCLee2o",
        "colab_type": "code",
        "outputId": "b182d994-5d0a-4326-9191-1081d0c634fc",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 70
        }
      },
      "cell_type": "code",
      "source": [
        "print(train_data.examples[15].text)\n",
        "print(train_data.examples[15].label)"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "['I', 'loved', 'this', 'film', '.', 'I', 'thought', 'it', 'would', 'be', 'easy', 'to', 'watch', ',', 'and', 'easy', 'to', 'forget', '.', 'I', 'ran', 'out', 'after', 'watching', 'this', 'to', 'buy', 'the', 'DVD', ',', 'obv', 'not', 'easily', 'forgotten!<br', '/><br', '/>The', 'script', 'is', 'brilliant', ',', 'and', 'the', 'casting', 'could', \"n't\", 'be', 'more', 'perfect', '.', 'Each', 'character', 'has', 'their', 'moment', ',', 'and', 'I', 'laughed', 'hard', 'throughout', 'this', 'film', ',', 'comedic', 'timing', 'was', 'spot', '-', 'on.<br', '/><br', '/', '>']\n",
            "pos\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "u3R5sgSme-Tt",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        },
        "outputId": "409af07c-c5ba-4c87-ae61-d2b3ab881663"
      },
      "cell_type": "code",
      "source": [
        "# word2vec, glove\n",
        "TEXT.build_vocab(train_data, max_size=10000, vectors='glove.6B.100d')\n",
        "LABEL.build_vocab(train_data)\n",
        "\n",
        "\n",
        "batchsz = 100\n",
        "device = torch.device('cuda')\n",
        "train_iterator, test_iterator = data.BucketIterator.splits(\n",
        "    (train_data, test_data),\n",
        "    batch_size = batchsz,\n",
        "    device=device\n",
        ")"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            ".vector_cache/glove.6B.zip: 862MB [01:10, 12.1MB/s]                           \n",
            "100%|█████████▉| 399630/400000 [00:21<00:00, 19336.50it/s]"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "metadata": {
        "id": "PBKKxxFBgRTM",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "class RNN(nn.Module):\n",
        "    \n",
        "    def __init__(self, vocab_size, embedding_dim, hidden_dim):\n",
        "        \"\"\"\n",
        "        \"\"\"\n",
        "        super(RNN, self).__init__()\n",
        "        \n",
        "        # [0-10001] => [100]\n",
        "        self.embedding = nn.Embedding(vocab_size, embedding_dim)\n",
        "        # [100] => [256]\n",
        "        self.rnn = nn.LSTM(embedding_dim, hidden_dim, num_layers=2, \n",
        "                           bidirectional=True, dropout=0.5)\n",
        "        # [256*2] => [1]\n",
        "        self.fc = nn.Linear(hidden_dim*2, 1)\n",
        "        self.dropout = nn.Dropout(0.5)\n",
        "        \n",
        "        \n",
        "    def forward(self, x):\n",
        "        \"\"\"\n",
        "        x: [seq_len, b] vs [b, 3, 28, 28]\n",
        "        \"\"\"\n",
        "        # [seq, b, 1] => [seq, b, 100]\n",
        "        embedding = self.dropout(self.embedding(x))\n",
        "        \n",
        "        # output: [seq, b, hid_dim*2]\n",
        "        # hidden/h: [num_layers*2, b, hid_dim]\n",
        "        # cell/c: [num_layers*2, b, hid_di]\n",
        "        output, (hidden, cell) = self.rnn(embedding)\n",
        "        \n",
        "        # [num_layers*2, b, hid_dim] => 2 of [b, hid_dim] => [b, hid_dim*2]\n",
        "        hidden = torch.cat([hidden[-2], hidden[-1]], dim=1)\n",
        "        \n",
        "        # [b, hid_dim*2] => [b, 1]\n",
        "        hidden = self.dropout(hidden)\n",
        "        out = self.fc(hidden)\n",
        "        \n",
        "        return out"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "cxq70oc9lK-4",
        "colab_type": "code",
        "outputId": "30e90284-6783-428c-e8a8-dd7ec4f89dae",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 151
        }
      },
      "cell_type": "code",
      "source": [
        "rnn = RNN(len(TEXT.vocab), 100, 256)\n",
        "\n",
        "pretrained_embedding = TEXT.vocab.vectors\n",
        "print('pretrained_embedding:', pretrained_embedding.shape)\n",
        "rnn.embedding.weight.data.copy_(pretrained_embedding)\n",
        "print('embedding layer inited.')\n",
        "\n",
        "optimizer = optim.Adam(rnn.parameters(), lr=1e-3)\n",
        "criteon = nn.BCEWithLogitsLoss().to(device)\n",
        "rnn.to(device)\n"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "pretrained_embedding: torch.Size([10002, 100])\n",
            "embedding layer inited.\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "RNN(\n",
              "  (embedding): Embedding(10002, 100)\n",
              "  (rnn): LSTM(100, 256, num_layers=2, dropout=0.5, bidirectional=True)\n",
              "  (fc): Linear(in_features=512, out_features=1, bias=True)\n",
              "  (dropout): Dropout(p=0.5)\n",
              ")"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "metadata": {
        "id": "_Rw_PZsZnBuJ",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "\n",
        "def binary_acc(preds, y):\n",
        "    \"\"\"\n",
        "    get accuracy\n",
        "    \"\"\"\n",
        "    preds = torch.round(torch.sigmoid(preds))\n",
        "    correct = torch.eq(preds, y).float()\n",
        "    acc = correct.sum() / len(correct)\n",
        "    return acc\n",
        "\n",
        "def train(rnn, iterator, optimizer, criteon):\n",
        "    \n",
        "    avg_acc = []\n",
        "    rnn.train()\n",
        "    \n",
        "    for i, batch in enumerate(iterator):\n",
        "        \n",
        "        # [seq, b] => [b, 1] => [b]\n",
        "        pred = rnn(batch.text).squeeze(1)\n",
        "        # \n",
        "        loss = criteon(pred, batch.label)\n",
        "        acc = binary_acc(pred, batch.label).item()\n",
        "        avg_acc.append(acc)\n",
        "        \n",
        "        optimizer.zero_grad()\n",
        "        loss.backward()\n",
        "        optimizer.step()\n",
        "        \n",
        "        if i%10 == 0:\n",
        "            print(i, acc)\n",
        "        \n",
        "    avg_acc = np.array(avg_acc).mean()\n",
        "    print('avg acc:', avg_acc)\n",
        "    \n",
        "    \n",
        "def eval(rnn, iterator, criteon):\n",
        "    \n",
        "    avg_acc = []\n",
        "    \n",
        "    rnn.eval()\n",
        "    \n",
        "    with torch.no_grad():\n",
        "        for batch in iterator:\n",
        "\n",
        "            # [b, 1] => [b]\n",
        "            pred = rnn(batch.text).squeeze(1)\n",
        "\n",
        "            #\n",
        "            loss = criteon(pred, batch.label)\n",
        "\n",
        "            acc = binary_acc(pred, batch.label).item()\n",
        "            avg_acc.append(acc)\n",
        "        \n",
        "    avg_acc = np.array(avg_acc).mean()\n",
        "    \n",
        "    print('>>test:', avg_acc)\n",
        "        \n",
        "    \n",
        "    "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "lrjzCiiao4Qw",
        "colab_type": "code",
        "outputId": "eb216fbe-f115-4aef-c294-7916f813cb95",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 4553
        }
      },
      "cell_type": "code",
      "source": [
        "for epoch in range(10):\n",
        "    \n",
        "    eval(rnn, test_iterator, criteon)\n",
        "    train(rnn, train_iterator, optimizer, criteon)"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            ">>test: 0.7121199841499328\n",
            "0 0.7400000095367432\n",
            "10 0.7799999713897705\n",
            "20 0.7299999594688416\n",
            "30 0.699999988079071\n",
            "40 0.7699999809265137\n",
            "50 0.7299999594688416\n",
            "60 0.7599999904632568\n",
            "70 0.6899999976158142\n",
            "80 0.75\n",
            "90 0.699999988079071\n",
            "100 0.6699999570846558\n",
            "110 0.7400000095367432\n",
            "120 0.7899999618530273\n",
            "130 0.8199999928474426\n",
            "140 0.85999995470047\n",
            "150 0.7899999618530273\n",
            "160 0.8299999833106995\n",
            "170 0.8299999833106995\n",
            "180 0.8199999928474426\n",
            "190 0.8700000047683716\n",
            "200 0.8499999642372131\n",
            "210 0.7899999618530273\n",
            "220 0.9099999666213989\n",
            "230 0.8299999833106995\n",
            "240 0.8399999737739563\n",
            "avg acc: 0.8027199811935425\n",
            ">>test: 0.8592799797058105\n",
            "0 0.7999999523162842\n",
            "10 0.8799999952316284\n",
            "20 0.8999999761581421\n",
            "30 0.85999995470047\n",
            "40 0.8799999952316284\n",
            "50 0.8899999856948853\n",
            "60 0.8199999928474426\n",
            "70 0.7899999618530273\n",
            "80 0.9099999666213989\n",
            "90 0.8499999642372131\n",
            "100 0.8799999952316284\n",
            "110 0.85999995470047\n",
            "120 0.8899999856948853\n",
            "130 0.8700000047683716\n",
            "140 0.8899999856948853\n",
            "150 0.85999995470047\n",
            "160 0.8899999856948853\n",
            "170 0.9399999976158142\n",
            "180 0.85999995470047\n",
            "190 0.8899999856948853\n",
            "200 0.8100000023841858\n",
            "210 0.8100000023841858\n",
            "220 0.8899999856948853\n",
            "230 0.8700000047683716\n",
            "240 0.9399999976158142\n",
            "avg acc: 0.8747199795246124\n",
            ">>test: 0.8693599815368652\n",
            "0 0.8999999761581421\n",
            "10 0.9099999666213989\n",
            "20 0.9099999666213989\n",
            "30 0.9599999785423279\n",
            "40 0.8299999833106995\n",
            "50 0.8299999833106995\n",
            "60 0.8499999642372131\n",
            "70 0.8799999952316284\n",
            "80 0.9300000071525574\n",
            "90 0.8499999642372131\n",
            "100 0.9199999570846558\n",
            "110 0.8999999761581421\n",
            "120 0.8499999642372131\n",
            "130 0.8499999642372131\n",
            "140 0.8499999642372131\n",
            "150 0.8799999952316284\n",
            "160 0.8799999952316284\n",
            "170 0.8799999952316284\n",
            "180 0.9399999976158142\n",
            "190 0.9300000071525574\n",
            "200 0.8899999856948853\n",
            "210 0.8899999856948853\n",
            "220 0.8799999952316284\n",
            "230 0.8899999856948853\n",
            "240 0.8899999856948853\n",
            "avg acc: 0.8864799809455871\n",
            ">>test: 0.8809999797344208\n",
            "0 0.9300000071525574\n",
            "10 0.8700000047683716\n",
            "20 0.8700000047683716\n",
            "30 0.9099999666213989\n",
            "40 0.8999999761581421\n",
            "50 0.9099999666213989\n",
            "60 0.8299999833106995\n",
            "70 0.8899999856948853\n",
            "80 0.8899999856948853\n",
            "90 0.8999999761581421\n",
            "100 0.8799999952316284\n",
            "110 0.8999999761581421\n",
            "120 0.9300000071525574\n",
            "130 0.9300000071525574\n",
            "140 0.8899999856948853\n",
            "150 0.8899999856948853\n",
            "160 0.8999999761581421\n",
            "170 0.9099999666213989\n",
            "180 0.8799999952316284\n",
            "190 0.8899999856948853\n",
            "200 0.8899999856948853\n",
            "210 0.8700000047683716\n",
            "220 0.8799999952316284\n",
            "230 0.9300000071525574\n",
            "240 0.85999995470047\n",
            "avg acc: 0.9025199830532074\n",
            ">>test: 0.8413999783992767\n",
            "0 0.85999995470047\n",
            "10 0.8799999952316284\n",
            "20 0.8899999856948853\n",
            "30 0.8899999856948853\n",
            "40 0.8799999952316284\n",
            "50 0.9599999785423279\n",
            "60 0.9199999570846558\n",
            "70 0.9099999666213989\n",
            "80 0.85999995470047\n",
            "90 0.8499999642372131\n",
            "100 0.8999999761581421\n",
            "110 0.8899999856948853\n",
            "120 0.8999999761581421\n",
            "130 0.9399999976158142\n",
            "140 0.8299999833106995\n",
            "150 0.8799999952316284\n",
            "160 0.8799999952316284\n",
            "170 0.9199999570846558\n",
            "180 0.9300000071525574\n",
            "190 0.9199999570846558\n",
            "200 0.9300000071525574\n",
            "210 0.8799999952316284\n",
            "220 0.8899999856948853\n",
            "230 0.9300000071525574\n",
            "240 0.9699999690055847\n",
            "avg acc: 0.9130399823188782\n",
            ">>test: 0.8841599793434143\n",
            "0 0.9399999976158142\n",
            "10 0.9199999570846558\n",
            "20 0.8799999952316284\n",
            "30 0.9300000071525574\n",
            "40 0.949999988079071\n",
            "50 0.9899999499320984\n",
            "60 0.9099999666213989\n",
            "70 0.9399999976158142\n",
            "80 0.9099999666213989\n",
            "90 0.9399999976158142\n",
            "100 0.9199999570846558\n",
            "110 0.9599999785423279\n",
            "120 0.9599999785423279\n",
            "130 0.9599999785423279\n",
            "140 0.9599999785423279\n",
            "150 0.8999999761581421\n",
            "160 0.9599999785423279\n",
            "170 0.9599999785423279\n",
            "180 0.949999988079071\n",
            "190 0.8999999761581421\n",
            "200 0.9399999976158142\n",
            "210 0.9300000071525574\n",
            "220 0.8899999856948853\n",
            "230 0.9099999666213989\n",
            "240 0.9599999785423279\n",
            "avg acc: 0.9244399819374084\n",
            ">>test: 0.8333199808597564\n",
            "0 0.9099999666213989\n",
            "10 0.9300000071525574\n",
            "20 0.9199999570846558\n",
            "30 0.9199999570846558\n",
            "40 0.9199999570846558\n",
            "50 0.9199999570846558\n",
            "60 0.9799999594688416\n",
            "70 0.949999988079071\n",
            "80 0.9599999785423279\n",
            "90 0.9599999785423279\n",
            "100 0.9300000071525574\n",
            "110 0.949999988079071\n",
            "120 0.949999988079071\n",
            "130 0.9599999785423279\n",
            "140 0.8799999952316284\n",
            "150 0.9300000071525574\n",
            "160 0.9599999785423279\n",
            "170 0.9399999976158142\n",
            "180 0.9199999570846558\n",
            "190 0.949999988079071\n",
            "200 0.8899999856948853\n",
            "210 0.9300000071525574\n",
            "220 0.949999988079071\n",
            "230 0.9099999666213989\n",
            "240 0.9300000071525574\n",
            "avg acc: 0.9306799817085266\n",
            ">>test: 0.8875999801158905\n",
            "0 0.9399999976158142\n",
            "10 0.9300000071525574\n",
            "20 0.9399999976158142\n",
            "30 0.9199999570846558\n",
            "40 0.9300000071525574\n",
            "50 0.949999988079071\n",
            "60 0.9199999570846558\n",
            "70 0.9199999570846558\n",
            "80 0.9399999976158142\n",
            "90 0.9599999785423279\n",
            "100 0.9599999785423279\n",
            "110 0.9199999570846558\n",
            "120 0.9199999570846558\n",
            "130 0.949999988079071\n",
            "140 0.949999988079071\n",
            "150 0.9199999570846558\n",
            "160 0.9399999976158142\n",
            "170 0.9599999785423279\n",
            "180 0.9399999976158142\n",
            "190 0.9300000071525574\n",
            "200 0.9599999785423279\n",
            "210 0.8999999761581421\n",
            "220 0.8799999952316284\n",
            "230 0.949999988079071\n",
            "240 0.9399999976158142\n",
            "avg acc: 0.9387199828624725\n",
            ">>test: 0.886599979877472\n",
            "0 0.9399999976158142\n",
            "10 0.9300000071525574\n",
            "20 0.9699999690055847\n",
            "30 0.9300000071525574\n",
            "40 0.9300000071525574\n",
            "50 0.9300000071525574\n",
            "60 0.9399999976158142\n",
            "70 0.9799999594688416\n",
            "80 0.9199999570846558\n",
            "90 0.9300000071525574\n",
            "100 0.9599999785423279\n",
            "110 0.949999988079071\n",
            "120 0.9699999690055847\n",
            "130 0.9399999976158142\n",
            "140 0.9399999976158142\n",
            "150 0.9399999976158142\n",
            "160 0.9399999976158142\n",
            "170 0.9599999785423279\n",
            "180 0.949999988079071\n",
            "190 0.9300000071525574\n",
            "200 0.9399999976158142\n",
            "210 0.9300000071525574\n",
            "220 0.9199999570846558\n",
            "230 0.9699999690055847\n",
            "240 0.9699999690055847\n",
            "avg acc: 0.9440799813270568\n",
            ">>test: 0.8887999806404113\n",
            "0 0.9799999594688416\n",
            "10 0.9199999570846558\n",
            "20 0.9099999666213989\n",
            "30 0.9899999499320984\n",
            "40 0.9699999690055847\n",
            "50 0.9199999570846558\n",
            "60 0.9399999976158142\n",
            "70 0.949999988079071\n",
            "80 0.9199999570846558\n",
            "90 0.8999999761581421\n",
            "100 0.9199999570846558\n",
            "110 0.949999988079071\n",
            "120 0.9199999570846558\n",
            "130 0.949999988079071\n",
            "140 0.9199999570846558\n",
            "150 0.8999999761581421\n",
            "160 0.9399999976158142\n",
            "170 0.9099999666213989\n",
            "180 0.9599999785423279\n",
            "190 0.9799999594688416\n",
            "200 0.9199999570846558\n",
            "210 0.9399999976158142\n",
            "220 0.9699999690055847\n",
            "230 0.8899999856948853\n",
            "240 0.949999988079071\n",
            "avg acc: 0.9476799790859223\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}